﻿package com.neriksworkshop.lib.colourLovers 
{
	import com.neriksworkshop.lib.colourLovers.requests.params.Format;
	import com.neriksworkshop.lib.colourLovers.requests.params.OrderCol;
	import com.neriksworkshop.lib.colourLovers.requests.IRequest;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author ...
	 */
	public class RequestManager extends EventDispatcher
	{
		
		private static var instance:RequestManager;

		
		public function RequestManager(inst:SingletonBlocker) 
		{
			
		}
		
		public static function getInstance():RequestManager
		{
			if (instance == null)
			{
				instance = new RequestManager(new SingletonBlocker());
			}
			return instance;
		}		
		
		
		public function sendRequest(req:IRequest):int
		{
			return req.load();
			/*
			var ul:UIdURLLoader = new UIdURLLoader();
			var ur:URLRequest = new URLRequest(req.serviceUrl);

			if (req.format == Format.FMT_XML)
			{
				ul.addEventListener(Event.COMPLETE, onXmlComplete);
				ul.load(ur);
			}
			else
			{
				
			}
			
			return ul.UId;*/
		}
		
		public function sendRequests(...requests):/*int*/Array
		{
			var ids:Array = [];
			for each (var request:IRequest in requests)  ids.push(request.load());
			return ids;
		}
		
		public function stopAll():void
		{
			//TODO implement StopAll method
		}
		
		
		

	}
	
}

internal class SingletonBlocker {}